package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;


/**
 * 
 * @Author (Alexander Hvidberg, Dennis Kirkebak & Thomas Kulmbach)
 * @Team (Group 1)
 * @Version (08/11/13)
 * 
 */
public class RentalCtr
{
    // instance variables
    private static RentalCtr instance;
    private RentalContainer rentalContainer;
    private AddressCtr addrCtr;
    private DVDCtr dvdCtr;

    /**
     * Constructor for objects of class RentalCtr
     */
    private RentalCtr()
    {
        // initialise instance variables
        rentalContainer = RentalContainer.getInstance();
        addrCtr = AddressCtr.getInstance();
        dvdCtr = DVDCtr.getInstance();
    }
    
    /**
     * Singleton.
     */
    public static RentalCtr getInstance()
    {
        if(instance == null) {
            instance = new RentalCtr();
        }
        return instance;
    }
    
    public void findRental(int id)
    {
        Rental r = rentalContainer.findRental(id);
        if(r!=null) {
            r.printDetails();
        }
        else {
            System.out.println("There is no Rental with this ID.");
        }
    }
    
    public void createRental(String date, int period, String phone, int id)
    {
        Person p = addrCtr.returnPersonByPhone(phone);
        if(p==null){
            System.out.println("The person doesnt exist");
        }
        else{
        
            DVD d = dvdCtr.returnDVD(id);
            rentalContainer.createRental(date, period, p, d);
        }
    }
    
    public void deleteRental(int id)
    {
        Rental r = rentalContainer.findRental(id);
        if(r!=null){
            rentalContainer.deleteRental(id);
            System.out.println("The rental has been deleted");
        }
        else{
            System.out.println("The rental does not exist!");
        }
    }
    
    public void printRentalList()
    {
        rentalContainer.printRentalList();
    }
    
    public ArrayList listAllRentals()
    {
        return rentalContainer.getRentalList();
    }
}
